/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package nl.hanze.web.ola;

import java.io.*;
import java.util.HashMap;

/**
 *
 * @author Luuk
 */
public class AcceptGiroFileReader {
    
    private BufferedReader br;
    private DataInputStream in;
    private FileInputStream fstream;
    private HashMap<String, String> data = new HashMap();
    
    public AcceptGiroFileReader(File file){
        try{
            fstream = new FileInputStream(file);
            in = new DataInputStream(fstream);
            br = new BufferedReader(new InputStreamReader(in));
        } catch (IOException e){
            System.out.println(e);
        }
        data.put("reference", null);
        data.put("bedrag", null);
        data.put("betalingskenmerk", null);
        data.put("rekeningnummer", null);
        data.put("geslacht", null);
        data.put("init", null);
        data.put("achternaam", null);
        data.put("straatnaam", null);
        data.put("straatnummer", null);
        data.put("postcode", null);
        data.put("plaatsnaam", null);
        data.put("rekeningnummernaar", null);
        data.put("naamnaar", null);
    }
    
    public HashMap<String, String> readFile(){
         try{
            String strLine;
            
            while ((strLine = br.readLine()) != null)   {
                String[] inc = strLine.split("=");
                if(inc[0].toLowerCase().equals("bedrag")){
                    String[] bedrag = inc[1].split(",");
                    data.put("euro", bedrag[0]);
                    data.put("cent", bedrag[1]);
                }else{
                    data.put(inc[0].toLowerCase(), inc[1]);
                }
            }
            in.close();
         } catch (Exception e) {
            System.err.println("Error: " + e.getMessage());
         }
         return data;
    }
}
